﻿<div ng-controller="DepotCommodityListC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">仓库商品管理</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">
                    <button class="btn btn-sm btn-default" ng-click="$state.go('app.Supplier_AddDepotCommodity', { 'id': $stateParams.id })">
                        <i class="fa fa-plus text"></i>
                        <span class="text">添加</span>
                    </button>
                    <button ng-if="istrue" class="btn btn-sm btn-default" ng-click="goadd()">
                        <i class="fa fa-plus text"></i>
                        <span class="text">修改整页</span>
                    </button>
                    <button ng-if="!istrue" class="btn btn-sm btn-default" ng-click="gosub()">
                        <i class="fa fa-plus text"></i>
                        <span class="text">完成修改</span>
                    </button>
                </div>
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 input-group">
                    <input type="text" class="form-control" placeholder="按名称查找" ng-model="findname">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="find()">查找</button>
                    </span>
                </div>
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light">
                    <thead>
                    <tr>
                        <th style="text-align: center;">名称</th>
                        <th style="text-align: center;">单价</th>
                        <th style="text-align: center;">库存</th>
                        <!--<th style="text-align: center;">操作</th>-->

                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="item in pageData">
                        <td style="width: 40%">{{item.Commodity.Brand}}/{{item.Commodity.Name}}/{{item.Commodity.Format}}/{{item.Commodity.Standard}}</td>
                        <td style="width: 30%"><input ng-disabled="istrue" ng-model="item.Price" type="number" min="0" class="form-control" required placeholder="请输入商品库存"></td>
                        <td style="width: 30%"><input ng-disabled="istrue" ng-model="item.Amount" type="number" min="0" class="form-control" required placeholder="请输入商品库存"></td>

                        <!--<td style="width: 20%">-->
                            <!--<button class="btn btn-sm btn-default" ng-click="commedit()">-->
                                <!--<i class="fa fa-plus text"></i>-->
                                <!--<span class="text">编辑</span>-->
                            <!--</button>-->
                        <!--</td>-->
                    </tr>
                    </tbody>
                </table>
                <!--<div class="panel-heading" ng-include="'/htm/tpl/Supplier/Paging.html'">-->

                <!--</div>-->
            </div>
        </div>
    </div>
</div>
<script>
    angular.module('app')//仓库商品列表
            .controller("DepotCommodityListC", function ($scope, $state, $http, $stateParams) {
                $scope.pageData = {};
                $scope.pageData.Page = 1;
                $scope.findname = "";

                $scope.pageData.Rows = $scope.defPageRows;
                $scope.istrue = true;
//                $scope.commedit = function(){
//                    $state.go('app.Supplier_Edit', { 'id': $stateParams.id })
//                };
                $scope.getData = function (p, r) {
                    if (p) {
                        p = p < 1 ? 1 : p;
                    } else p = 1;
                    if (r) {
                    } else r = $scope.defPageRows;
                    $http({
                        url: "/api/Provider/DepotCommodity",
                        method: "GET",
                        params: {depotId:$stateParams.id,name:$scope.findname,page:p,rows:r}
                        })
                            .then(function (res) {
                                $scope.pageData = res.data;
                                console.log($scope.pageData);
                            })
                            .then(function (error) {
                                if (error) {
                                    alert("数据获取失败");
                                }
                            });
                };
                $scope.getData(1, $scope.pageData.Rows);
                $scope.find = function(){
                    $scope.getData(1, $scope.pageData.Rows);
                };
                $scope.goadd = function(){
                    $scope.istrue = !$scope.istrue;
                };
                $scope.gosub = function (){
                    $http.put('../api/Provider/EditProviderCommodity' , $scope.pageData)
                            .success(function(){
                                alert("批量修改成功");
                                $state.go('app.Supplier_ProviderCommodityList', { 'id': $stateParams.id });
                            });
                };
            })

</script>
